package com.igoal.campaign.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.igoal.campaign.entity.Campaign;
import com.igoal.dao.GenericDaoHibernate;
import com.igoal.entity.DataStatus;

public class CampaignDAOImpl extends GenericDaoHibernate<Campaign, Long>
		implements CampaignDAO {

	public CampaignDAOImpl() {
		super(Campaign.class);
	}
	
	public Campaign getCampaignByName(String name){
		DetachedCriteria dc = DetachedCriteria.forClass(Campaign.class);
		dc.add(Restrictions.eq("campaignName", name));
		getByStatus(dc, DataStatus.USING);
		
		List<Campaign> result = findByCriteria(dc, 0, 1);
		if(result.size() == 0)
			return null;
		
		return result.get(0);
	}

}
